home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 12 / Engine / SoundSystem.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  2.3 KB  |  74 lines

  1. //-----------------------------------------------------------------------------
  2. // A wrapper class for playing audio files through the DirectMusic interfaces.
  3. // The audio path 3D class allows for 3D playback.
  4. //
  5. // Programming a Multiplayer First Person Shooter in DirectX
  6. // Copyright (c) 2004 Vaughan Young
  7. //-----------------------------------------------------------------------------
  8. #ifndef SOUND_SYSTEM_H
  9. #define SOUND_SYSTEM_H
  10.  
  11. //-----------------------------------------------------------------------------
  12. // Sound System Class
  13. //-----------------------------------------------------------------------------
  14. class SoundSystem
  15. {
  16. public:
  17.     SoundSystem( float scale = 1.0f );
  18.     virtual ~SoundSystem();
  19.  
  20.     void UpdateListener( D3DXVECTOR3 forward, D3DXVECTOR3 position, D3DXVECTOR3 velocity );
  21.  
  22.     void GarbageCollection();
  23.  
  24.     void SetVolume( long volume );
  25.  
  26.     IDirectMusicLoader8 *GetLoader();
  27.     IDirectMusicPerformance8 *GetPerformance();
  28.  
  29. private:
  30.     float m_scale; // Unit scale in meters/unit.
  31.     IDirectMusicLoader8 *m_loader; // DirectMusic loader.
  32.     IDirectMusicPerformance8 *m_performance; // DirectMusic performance.
  33.     IDirectSound3DListener8 *m_listener; // DirectSound 3D listener.
  34. };
  35.  
  36. //-----------------------------------------------------------------------------
  37. // Sound Class
  38. //-----------------------------------------------------------------------------
  39. class Sound
  40. {
  41. public:
  42.     Sound( char *filename );
  43.     virtual ~Sound();
  44.  
  45.     void Play( bool loop = false, unsigned long flags = DMUS_SEGF_AUTOTRANSITION );
  46.  
  47.     IDirectMusicSegment8 *GetSegment();
  48.  
  49. private:
  50.     IDirectMusicSegment8 *m_segment; // DirectMusic segment for the sound.
  51. };
  52.  
  53.  
  54. //-----------------------------------------------------------------------------
  55. // Audio Path 3D Class
  56. //-----------------------------------------------------------------------------
  57. class AudioPath3D
  58. {
  59. public:
  60.     AudioPath3D();
  61.     virtual ~AudioPath3D();
  62.  
  63.     void SetPosition( D3DXVECTOR3 position );
  64.     void SetVelocity( D3DXVECTOR3 velocity );
  65.     void SetMode( unsigned long mode );
  66.  
  67.     void Play( IDirectMusicSegment8 *segment, bool loop = false, unsigned long flags = DMUS_SEGF_SECONDARY );
  68.  
  69. private:
  70.     IDirectMusicAudioPath8 *m_audioPath; // DirectMusic audio path for 3D playback.
  71.     IDirectSound3DBuffer8 *m_soundBuffer; // Pointer to the audiopath's sound buffer.
  72. };
  73.  
  74. #endif